package com.atguigu4.search_sort.exer2;

/**
 * ClassName: Erfenfaseach
 * Package: com.atguigu4.search_sort.exer2
 * Description:
 *
 * @Author xiao_qi
 * @Create 2024/3/15 22:31
 * @Version 1.0
 */
public class Erfenfaseach {
    public static void main(String[] args) {
        int[] arr2 = new int[]{2,4,5,8,12,15,19,26,37,49,51,66,89,100};
        int target =5;
        int end = arr2.length - 1,head = 0;
        int middle = (end+head)/2;

        boolean isflag = false;
        while (head <= end){
            middle = (end+head)/2;
            if (arr2[middle] == target) {
                System.out.println("找到了目标:" + target + "下标为：" + middle);
                isflag = true;
                break;
            }
            if(arr2[middle] < target){
                head = middle +1;
            }
            if(arr2[middle] > target){
                end = middle - 1;
            }
        }
        if (isflag == false) {
            System.out.println("在数组中没找到数字为：" + target + "目标");
        }
    }
}
